﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTOSingTowerMall;

namespace BLSingTowerMall
{
    public class PromotionBookingProcess
    {
        public bool bookPromotion(ICampaign newBooking)
        {
            using (DBSingTowerMallEntities cntx = new DBSingTowerMallEntities())
            {
                
                Campaign promoBooking = new Campaign();

                int lastBookID = cntx.Campaigns.Max(x => x.CampaignID);

                promoBooking.BlockID = newBooking.BlockID;
                promoBooking.CampaignID = lastBookID + 1;
                promoBooking.StartPeriod = newBooking.StartPeriod;
                promoBooking.EndPeriod = newBooking.EndPeriod;
                promoBooking.Title = newBooking.Title;
                promoBooking.Description = newBooking.Description;
                promoBooking.ImagePath = newBooking.ImagePath;

                cntx.AddToCampaigns(promoBooking);

                cntx.SaveChanges();
            }
            return true;
        }

        public int getBlockIdbyStoreId(int storeId)
        {
            using (DBSingTowerMallEntities cntx = new DBSingTowerMallEntities())
            {
                var blockId = (from f in cntx.Stores
                              where f.StoreID ==storeId
                              select f.BlockID).FirstOrDefault();// .FirstOrDefault(m => m.StoreID = storeId); 
                                  //cntx.Stores.FirstOrDefault(m => m.StoreID = storeId);

                return blockId;
            }
        }
    }
}
